<?php 
 class LoginController extends Controller{
 	public function out(){
 		session_unset();
 		session_destroy();
 		$this->success('退出成功！','login');

 	}
 	public function login(){
 		if (IS_POST) {
 			$username = Q('username');
            $password = Q('password', '', '');
            if (!$username) {
                $this->error('帐号不能为空');
            }
            if (!$password) {
                $this->error('密码不能为空');
            }
            $user = M('admin')->where("username='{$username}'")->find();
            if (empty($user)) {
                $this->error('帐号不存在');
            }
            if ($user['password'] != md5($password)) {
                $this->error('密码错误');
            }
            $_SESSION['aid'] = $user['aid'];
            $_SESSION['username'] = $user['username'];
            go("Index/index");
 		}else{
 			$this->display();
 		}
 	}
 }


 ?>